# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.support import expected_conditions as ec
# from selenium.webdriver.support.ui import Select
# from selenium.webdriver.common.keys import Keys
# import os
#
#
# def openBrowser(browser="Chrome"):
#     """
#     打开浏览器
#     :param browser: 浏览器
#     :return:
#     """
#     driver = None
#     if browser == "Chrome":
#         driver = webdriver.Chrome()
#     elif browser == "Firefox":
#         driver = webdriver.Firefox()
#     elif browser == "Ie":
#         driver = webdriver.Ie()
#     else:
#         print("请输入正确的浏览器名称,例:Chrome Firefox Ie")
#     return driver
#
#
# class Base(object):
#     def __init__(self):
#         self.options = webdriver.ChromeOptions()
#         self.options.add_argument("start-maximized")
#         self.driver = webdriver.Chrome(options=self.options)
#
#     def getUrl(self, url):
#         """
#         打开网页
#         :param url: 网址
#         :return:
#         """
#         self.driver.get(url)
#
#     def find_element(self, locator, timeout=10):
#         try:
#             element = WebDriverWait(self.driver, timeout).until(ec.presence_of_element_located(locator))
#             return element
#         except Exception as e:
#             print(f"{locator}元素不存在", e)
#             return False
#
#     def find_class_elements(self, class_name, index):
#         try:
#             WebDriverWait(self.driver, 10).until(ec.presence_of_element_located((By.CLASS_NAME, class_name)))
#             element = self.driver.find_elements_by_class_name(class_name)[index]
#             return element
#         except Exception as e:
#             print(f"{class_name}元素不存在", e)
#             return False
#
#     def click(self, locator, timeout=10):
#         """
#         element点击元素
#         :return:
#         """
#         self.find_element(locator, timeout).click()
#
#     def clicks(self, class_name, index):
#         """
#         elements点击元素
#         :param class_name:
#         :param index:
#         :return:
#         """
#         self.find_class_elements(class_name, index).click()
#
#     def sendKeys(self, locator, timeout, content):
#         """
#         在元素中输入内容
#         :return:
#         """
#         element = self.find_element(locator, timeout)
#         element.clear()
#         element.send_keys(content)
#
#     def sendKeys1(self, locator, timeout, content):
#         """
#         在元素中输入内容(不清空)
#         :return:
#         """
#         element = self.find_element(locator, timeout)
#         print(element)
#         element.send_keys(content)
#
#     def getElementText(self, locator, timeout):
#         """
#         获取元素中的文本
#         :return: 文本
#         """
#         return self.find_element(locator, timeout).text
#
#     def close(self):
#         """
#         关闭浏览器
#         :return:
#         """
#         self.driver.close()
#
#     def elementIsEnabled(self, locator):
#         """
#         判断元素是否可用
#         :return:
#         """
#         element = self.find_element(locator)
#         return element.is_enabled()
#
#     def getAttribute(self, locator, attribute: str):
#         """
#         获取元素属性的值
#         :return:
#         """
#         text = self.find_element(locator).get_attribute(attribute)
#         return text
#
#     def switchAlert(self):
#         """
#         切换到弹窗
#         :return:
#         """
#         try:
#             al = self.driver.switch_to.alert
#             al.accept()
#         except Exception:
#             print("无提示信息")
#             return False
#
#     def switchIframe(self, locator):
#         """
#         切换到iframe
#         :return:
#         """
#         self.driver.switch_to.frame(self.find_element(locator))
#
#     def selectByText(self, locator, text):
#         """
#         选择下拉框 根据文本
#         :return:
#         """
#         select = Select(self.find_element(locator))
#         select.select_by_visible_text(text)
#
#     def sendKeysbyKEY(self, locator, text):
#         """
#         通过键盘事件删除数据再输入内容
#         :return:
#         """
#         element = self.find_element(locator)
#         element.send_keys(Keys.BACK_SPACE)
#         element.send_keys(text)
#
#     def get_screenshot(self, file_name):
#         pic_path = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "picture/")
#         self.driver.get_screenshot_as_file(pic_path + file_name)
#
#
# driver = Base()
